package me.ingxin.android.permission2.request

import me.ingxin.android.permission2.PermissionMediator
import me.ingxin.android.permission2.strategy.ReasonStrategy
import me.ingxin.android.permission2.view.Guide

/**
 * Created on 2023/7/1 by yin
 * 任务链-任务请求
 * @param reasonStrategy 理由对话框策略
 * @param skipRequestNormaPermission 是否跳过申请普通权限
 */
internal class Request private constructor(
    private val mediator: PermissionMediator,
    val reasonStrategy: ReasonStrategy,
    val skipRequestNormaPermission: Boolean
) {

    val normalPermissions: List<String>
        get() = mediator.normalPermissions

    val specialPermissions: List<String>
        get() = mediator.specialPermissions

    val settings: Boolean
        get() = mediator.settings

    val guide: Guide
        get() = mediator.getGuide()

    val tipsWhileRequest: Boolean
        get() = mediator.tipsWhileRequest


    fun newBuilder(): Builder = Builder(this)

    class Builder {

        private val mediator: PermissionMediator
        private var reasonStrategy: ReasonStrategy? = null
        private var skipRequestNormaPermission = false

        constructor(mediator: PermissionMediator) {
            this.mediator = mediator
        }

        constructor(request: Request) {
            this.mediator = request.mediator
            this.reasonStrategy = request.reasonStrategy
        }

        fun reasonStrategy(strategy: ReasonStrategy) = apply {
            this.reasonStrategy = strategy
        }

        fun skipRequestNormaPermission(enable: Boolean) = apply {
            this.skipRequestNormaPermission = enable
        }

        fun build(): Request =
            Request(mediator, reasonStrategy ?: mediator.reasonStrategy, skipRequestNormaPermission)

    }


}